package com.ruoyi.graduate.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.graduate.domain.entity.MsSysUser;
import com.ruoyi.graduate.domain.param.*;
import com.ruoyi.graduate.domain.vo.MsSysUserPageVo;
import com.ruoyi.graduate.domain.vo.MsUserOrderListVo;
import com.ruoyi.graduate.service.IMsPhotographyPackageService;
import com.ruoyi.graduate.service.IMsSysUserService;
import com.ruoyi.graduate.service.MsPhotographyOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户控制接口
 */
@RestController
@RequestMapping("/api/user")
@Api(tags = "用户控制接口")
public class MsSysUserController extends BaseController {



    @Autowired
    private IMsSysUserService msSysUserService;

    @Autowired
    private MsPhotographyOrderService msPhotographyOrderService;

    @ApiOperation("获取所有用户列表")
    @GetMapping("/all")
    public TableDataInfo all(MsSysUserPageParam param) {
        PageInfo pageInfo = msSysUserService.pageList(param);

        return getDataTable(pageInfo.getList(), pageInfo.getTotal());
    }

    @ApiOperation("获取摄影师列表")
    @GetMapping("/photoList")
    public AjaxResult photoList() {

        return AjaxResult.success(msSysUserService.photoList());
    }


    @ApiOperation("用户管理修改")
    @PutMapping
    public AjaxResult update(@RequestBody MsSysUserUpdataParam param) {

        return msSysUserService.updata(param);
    }



    @ApiOperation("删除用户")
    @DeleteMapping("{id}")
    public AjaxResult delete(@PathVariable Long id) {

        return msSysUserService.delete(id);
    }


    @ApiOperation("重置密码")
    @PutMapping("/reset")
    public AjaxResult reset(@RequestBody MsSysUserResetParam param) {

        return msSysUserService.reset(param);
    }


    @ApiOperation("用户管理新增用户")
    @PostMapping("/adduser")
    public AjaxResult addUser(@RequestBody MsSysUserAddParam param) {

        return msSysUserService.adduser(param);
    }


    @ApiOperation("用户端修改密码")
    @PutMapping("/resetPassword")
    public AjaxResult resetPassword(@RequestBody MsSysUserRestPasswordParam param) {

        return msSysUserService.resetPassword(param);
    }


    @ApiOperation("用户端获取订单列表")
    @GetMapping("/order/{userId}")
    public AjaxResult order(@PathVariable Long userId) {

        List<MsUserOrderListVo> msUserOrderListVos = msPhotographyOrderService.userList(userId);

        return AjaxResult.success(msUserOrderListVos);

    }

}
